var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
    value: !0
});
var o = e("BoxItem"),
    i = e("DataMgr"),
    a = e("VideoHint"),
    r = cc._decorator,
    s = r.ccclass,
    c = r.property,
    l = function (e) {
        __extends(t, e);
        function t() {
            var t = null !== e && e.apply(this, arguments) || this;
            t.boxItems = [];
            t.adBtnNode = null;
            t.adBtnNode2 = null;
            t.closeBtnNode = null;
            t.rewardArr = [100, 100, 150, 150, 200, 200, 300, 300, 500];
            t.restTime = 3;
            t.itemParent = null;
            t.panel = null;
            t.adBoxSprite = null;
            t.noAdBoxSprite = null;
            t.callBack = null;
            return t
        }
        n = t;
        t.prototype.onLoad = function () {
            n.Instance = this;
            this.boxItems = this.itemParent.getComponentsInChildren(o.default)
        };
        t.prototype.openBox = function (e) {
            var t = this;
            void 0 === e && (e = !0);
            n.openCount++;
            e && this.restTime--;
            0 == this.checkRestBox() && this.closePanel();
            this.scheduleOnce(function () {
                if (t.restTime <= 0) {
                    SDK.Mgr.Inst.curChannel == SDK.Define.Channel.tt && SDK.Mgr.Inst.isAdOpen ? t.adBtnNode2.active = !0 : t.adBtnNode.active = !0;
                    t.closeBtnNode.active = !0;
                    if (0 == t.checkRestBox()) t.closePanel();
                    else {
                        SDK.Mgr.Inst.curChannel == SDK.Define.Channel.vivo && SDK.Mgr.Inst.isAdOpen && t.delayShowInsert();
                        if (t.checkRestBox() <= 3) for (var e = 0; e < t.boxItems.length; e++) t.boxItems[e].setReward(t.rewardArr[e])
                    }
                } else 0 == t.checkRestBox() && t.closePanel()
            },
                .5)
        };
        t.prototype.delayShowInsert = function () {
            this.scheduleOnce(function () {
                // SDK.Mgr.Inst.curChannel != SDK.Define.Channel.android_oppo && 
                SDK.Mgr.Inst.showInsert()
            },
                .5)
        };
        t.prototype.checkRestBox = function () {
            var e = 0;
            this.boxItems.forEach(function (t) {
                t.hasOpen || e++
            });
            return e
        };
        t.prototype.openPanel = function (e) {
            this.panel.active = !0;
            this.callBack = e;
            SDK.Mgr.Inst.closeBanner();
            this.resetPanel();
            this.initData();
            this.scheduleOnce(function () {
                // SDK.Mgr.Inst.curChannel != SDK.Define.Channel.android_oppo && 
                SDK.Mgr.Inst.showInsert()
            },
                1)
        };
        t.prototype.resetPanel = function () {
            this.restTime = 3;
            this.adBtnNode.active = !1;
            this.adBtnNode2.active = !1;
            this.closeBtnNode.active = !1;
            for (var e = 0; e < this.boxItems.length; e++) this.boxItems[e].reset()
        };
        t.prototype.initData = function () {
            this.rewardArr.sort(function () {
                return .5 - Math.random()
            });
            var e = [0, 1, 2, 3, 4, 5, 6, 7, 8];
            e.sort(function () {
                return .5 - Math.random()
            });
            for (var t = 0; t < this.boxItems.length; t++) this.boxItems[t].setReward(this.rewardArr[t]);
            if (n.openCount > 1) for (t = 0; t < 3; t++) {
                SDK.Mgr.Inst.curChannel == SDK.Define.Channel.tt && this.boxItems[e[t]].AdBox();
                SDK.Mgr.Inst.curChannel == SDK.Define.Channel.oppo && SDK.Mgr.Inst.isAdOpen && this.boxItems[e[t]].AdBox()
            }
        };
        t.prototype.adBtnClick = function () {
            var e = "OpenBox_AddTimes_";
            SDK.Mgr.Inst.event(e + "ADClick");
            var t = this,
                n = function (o) {
                    if (o == SDK.Define.AdsCode.finish) {
                        SDK.Mgr.Inst.event(e + "ADSuccess");
                        t.restTime = 3;
                        t.adBtnNode.active = !1;
                        t.adBtnNode2.active = !1;
                        t.closeBtnNode.active = !1;
                        i.default.Instance.videoAdTimes++;
                        if (t.checkRestBox() <= 3) for (var r = 0; r < t.boxItems.length; r++) t.boxItems[r].hasOpen || t.boxItems[r].AdBox(!1)
                    } else if (o == SDK.Define.AdsCode.cancel) {
                        SDK.Mgr.Inst.event(e + "Cancel");
                        a.default.Instance.openPanel(n)
                    } else {
                        SDK.ToastMgr.Inst.showToast("暂无广告，请稍后再试");
                        SDK.Mgr.Inst.event(e + "NoAd")
                    }
                };
            SDK.Mgr.Inst.showVideo(n)
        };
        t.prototype.closePanel = function () {
            SDK.Mgr.Inst.showInsert()
            this.panel.active = !1;
            if (this.callBack) {
                this.callBack();
                this.callBack = null
            }
            SDK.Mgr.Inst.closeBanner();
            SDK.Mgr.Inst.curChannel == SDK.Define.Channel.oppo && SDK.Mini.OPPO.Extend.Inst.hasBoxAd() && SDK.Mgr.Inst.customData && SDK.Mgr.Inst.customData.openBoxBanner
        };
        var n;
        t.Instance = null;
        t.openCount = 0;
        __decorate([c(cc.Node)], t.prototype, "adBtnNode", void 0);
        __decorate([c(cc.Node)], t.prototype, "adBtnNode2", void 0);
        __decorate([c(cc.Node)], t.prototype, "closeBtnNode", void 0);
        __decorate([c(cc.Node)], t.prototype, "itemParent", void 0);
        __decorate([c(cc.Node)], t.prototype, "panel", void 0);
        __decorate([c(cc.SpriteFrame)], t.prototype, "adBoxSprite", void 0);
        __decorate([c(cc.SpriteFrame)], t.prototype, "noAdBoxSprite", void 0);
        return n = __decorate([s], t)
    }(cc.Component);
n.default = l